package com.ebs.md.fxmonitor.marketmonitor.model;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/model/AbsSingleFact.java $
 *  $Revision: #9 $  $Change: 115064 $  $DateTime: 2012/09/20 07:24:37 $  $Author: Arik.Sher $
 */

import java.io.Serializable;

import com.ebs.md.api.BookSide;
import com.ebs.md.api.Rate;
import com.ebs.md.api.product.PairProduct;
import com.ebs.md.fxmonitor.marketmonitor.config.INameableConfig;


public abstract class AbsSingleFact
implements Serializable
{
	// gened with Eclipse
	private static final long serialVersionUID = 721609828578750024L;

	public static final String BASIC_CONFIG_NAME = INameableConfig.BASIC_CONFIG_NAME;
	
	protected final String shortClassName = getClass().getSimpleName();

	protected String      configInstanceName;
	protected PairProduct pair;
	protected long        timestamp; // milliseconds since 1970

	protected String      quoteId;
	protected BookSide    bookSide;
	protected Rate        quoteRate;
	protected String      quoteRegion;

	protected long        availAmount = -12321; // -12321 means not initialized
	protected long        totalAmount = -12321; // -12321 means not initialized
	
	@Deprecated
	public AbsSingleFact(String configInstanceName, PairProduct pair, long timestamp, String quoteId, Rate quoteRate, BookSide bookSide) {
		super();
		this.configInstanceName = configInstanceName;
		this.pair = pair;
		this.timestamp = timestamp;
		this.quoteId = quoteId;
		this.quoteRate = quoteRate;
		this.bookSide = bookSide;
		// TODO: add amounts...
		// TODO: add region
	}
	
	public AbsSingleFact(String configInstanceName, AbsOBChange obChange) {
		super();
		this.configInstanceName = configInstanceName;
		this.pair = obChange.getPair();
		this.timestamp = obChange.getTimestamp();
		this.quoteId = obChange.getQuoteId();
		this.quoteRate = obChange.getRate();
		this.bookSide = obChange.getBookSide();
		this.availAmount = obChange.getAvailAmount();
		this.totalAmount = obChange.getTotalAmount();
		this.quoteRegion = obChange.getRegion();
	}
	
	public String getConfigInstanceName() {
		return configInstanceName;
	}

	public PairProduct getPair() {
		return pair;
	}

	public long getTimestamp() {
		return timestamp;
	}

	public String getQuoteId() {
		return quoteId;
	}

	public Rate getQuoteRate() {
		return quoteRate;
	}

	public BookSide getBookSide() {
		return bookSide;
	}

	public long getAvailAmount() {
		return availAmount;
	}

	public long getTotalAmount() {
		return totalAmount;
	}

	public String getQuoteRegion() {
		return quoteRegion;
	}

	// gened by eclipse on pair, timestamp, quoteId
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((pair == null) ? 0 : pair.hashCode());
		result = prime * result + ((quoteId == null) ? 0 : quoteId.hashCode());
		result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
		return result;
	}
	// gened by eclipse on pair, timestamp, quoteId
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbsSingleFact other = (AbsSingleFact) obj;
		if (pair == null) {
			if (other.pair != null)
				return false;
		} else if (!pair.equals(other.pair))
			return false;
		if (quoteId == null) {
			if (other.quoteId != null)
				return false;
		} else if (!quoteId.equals(other.quoteId))
			return false;
		if (timestamp != other.timestamp)
			return false;
		return true;
	}

	protected abstract String additionalFields4toString();

	public String toString() {
		return shortClassName 
			+  "[bookSide=" + bookSide 
			+ ", pair=" + pair.getName()
			+ ", configInstanceName=" + configInstanceName
			+ ", timestamp=" + getTimestamp()
			+ ", quoteId=" + quoteId
			+ ", quoteRate=" + quoteRate
			+ ", quoteAvailAmount=" + availAmount
			+ ", quoteTotalAmount=" + totalAmount
			+ ", quoteRegion=" + quoteRegion
			+ additionalFields4toString()
			+ "]";
	}

}
